<html>
<head><meta charset="utf-8"><title>Zeroize (https://crates.io/crates/zeroize) · wg-secure-code · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/index.html">wg-secure-code</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html">Zeroize (https://crates.io/crates/zeroize)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="135936646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135936646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Liebow-Feeser <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135936646">(Oct 16 2018 at 23:13)</a>:</h4>
<p>I actually talked to Erick Tryzelaar about this. I definitely want to see it ported to Fuchsia.</p>



<a name="135972793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135972793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135972793">(Oct 17 2018 at 13:31)</a>:</h4>
<p>awesome, thanks</p>



<a name="135972901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135972901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135972901">(Oct 17 2018 at 13:33)</a>:</h4>
<p>the API is potentially RFC-able. just a trait I've implemented for some of the core types: <a href="https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html" target="_blank" title="https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html">https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html</a></p>



<a name="135972944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135972944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135972944">(Oct 17 2018 at 13:33)</a>:</h4>
<p>if it got into <code>std</code>, there wouldn't be any need for OS-by-OS support, since it could provide a stable API for an underlying LLVM intrinsic (<code>volatile_set_memory</code> in this case)</p>



<a name="135986713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135986713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Liebow-Feeser <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135986713">(Oct 17 2018 at 17:16)</a>:</h4>
<p>Yeah, that sounds like the way to go.</p>



<a name="135992162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135992162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135992162">(Oct 17 2018 at 18:37)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> do you have any thoughts regarding stabilizing <code>volatile_set_memory</code> with an API like <a href="https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html" target="_blank" title="https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html">https://docs.rs/zeroize/latest/zeroize/trait.Zeroize.html</a></p>



<a name="135992174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135992174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135992174">(Oct 17 2018 at 18:37)</a>:</h4>
<p>well, <code>volatile_set_memory</code> that always sets things to 0</p>



<a name="135992502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135992502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135992502">(Oct 17 2018 at 18:42)</a>:</h4>
<p>even just a stable wrapper that does a volatile zero on a &amp;mut [u8] would be sufficient</p>



<a name="135996444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135996444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135996444">(Oct 17 2018 at 19:51)</a>:</h4>
<p>I don't have deep thoughts :)</p>



<a name="135996457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/135996457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#135996457">(Oct 17 2018 at 19:51)</a>:</h4>
<p>it seems like a .. probably fine thing; I imagine there will be some objections that the API on <code>[u8]</code> is too specific, but I'm not sure what the more general API should look like</p>



<a name="136000612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/136000612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#136000612">(Oct 17 2018 at 21:02)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> the <code>Zeroize</code> trait I linked above is an idea of what a more general API could look like. I guess the neat part is that much can be built out as a crate so long as there's some access to the intrinsic via core</p>



<a name="136001102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/136001102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#136001102">(Oct 17 2018 at 21:10)</a>:</h4>
<p>I think that the idea of adding a stable "intrinsic primitive" is pretty appealing, yes</p>



<a name="152120630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152120630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152120630">(Dec 18 2018 at 16:41)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> so <code>std::ptr::write_volatile</code> has the volatile write semantics a "zeroizer" needs, but appears to require alignment. <code>std::ptr::write_unaligned</code> can perform unaligned writes, but they aren't volatile</p>



<a name="152120718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152120718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152120718">(Dec 18 2018 at 16:42)</a>:</h4>
<p>I think the minimum viable primitive which could be used for a crate like <code>zeroize</code> but is also generally useful would be something like <code>std::ptr::write_unaligned_volatile</code> or <code>write_volatile_unaligned</code></p>



<a name="152134506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152134506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152134506">(Dec 18 2018 at 20:12)</a>:</h4>
<p>interesting</p>



<a name="152134516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152134516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152134516">(Dec 18 2018 at 20:12)</a>:</h4>
<p>it seems like there is no clear reason to couple those two things</p>



<a name="152136832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152136832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152136832">(Dec 18 2018 at 20:44)</a>:</h4>
<p>this would be as a stable wrapper for <code>core::intrinsics::volatile_set_memory</code></p>



<a name="152136881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152136881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152136881">(Dec 18 2018 at 20:45)</a>:</h4>
<p>which AFAIK has <code>write_unaligned_volatile</code> behavior</p>



<a name="152136910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152136910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152136910">(Dec 18 2018 at 20:45)</a>:</h4>
<p>but perhaps I'm misunderstanding how one or more of these handle alignment</p>



<a name="152136932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152136932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152136932">(Dec 18 2018 at 20:45)</a>:</h4>
<p>perhaps I can dig up some past discussion of this sort of thing</p>



<a name="152136998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152136998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152136998">(Dec 18 2018 at 20:46)</a>:</h4>
<p>the use case is zeroing out arbitrary byte slices which are not necessarily aligned</p>



<a name="152137365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137365">(Dec 18 2018 at 20:51)</a>:</h4>
<p><span class="user-mention" data-user-id="132721">@Tony Arcieri</span> a byte slice is always aligned since bytes have alignment 1.</p>



<a name="152137494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137494">(Dec 18 2018 at 20:52)</a>:</h4>
<p>Other libraries may be different, but in <em>ring</em> if we wanted to zeroize things, we'd never need to do so in an unaligned way. It seems weird that that would be a requirement.</p>



<a name="152137534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137534">(Dec 18 2018 at 20:54)</a>:</h4>
<p>Also, <code>write_volatile</code> is already <code>unsafe</code> so you could just cast the pointer to a <code>*mut u8</code> and it would work fine without any more <code>unsafe</code>.</p>



<a name="152137597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137597">(Dec 18 2018 at 20:54)</a>:</h4>
<p><span class="user-mention" data-user-id="133214">@briansmith</span> so I was a bit confused by <code>write_volatile</code>'s documentation</p>



<a name="152137611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137611">(Dec 18 2018 at 20:55)</a>:</h4>
<p>namely the Safety section: <a href="https://doc.rust-lang.org/std/ptr/fn.write_volatile.html#safety" target="_blank" title="https://doc.rust-lang.org/std/ptr/fn.write_volatile.html#safety">https://doc.rust-lang.org/std/ptr/fn.write_volatile.html#safety</a></p>



<a name="152137626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137626">(Dec 18 2018 at 20:55)</a>:</h4>
<p>and comments like this:</p>



<a name="152137628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137628">(Dec 18 2018 at 20:55)</a>:</h4>
<blockquote>
<p>Note that even if T has size 0, the pointer must be non-NULL and properly aligned.</p>
</blockquote>



<a name="152137667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137667">(Dec 18 2018 at 20:55)</a>:</h4>
<p>what does "aligned" mean in the context of a zero-sized type?</p>



<a name="152137673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137673">(Dec 18 2018 at 20:55)</a>:</h4>
<p>I assumed that meant "word aligned"</p>



<a name="152137734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137734">(Dec 18 2018 at 20:56)</a>:</h4>
<p>Maybe it it referring to things like <code>[u64; 0]</code>?</p>



<a name="152137748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137748">(Dec 18 2018 at 20:56)</a>:</h4>
<p>which presumably has alignment 4 or 8 but size 0</p>



<a name="152137758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137758">(Dec 18 2018 at 20:56)</a>:</h4>
<p>if <code>write_volatile</code> already does what I want, hallelujah</p>



<a name="152137794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137794">(Dec 18 2018 at 20:57)</a>:</h4>
<p>so if I have a variable-width byte slice, I could just iterate over it clearing it a byte-at-a-time?</p>



<a name="152137897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137897">(Dec 18 2018 at 20:58)</a>:</h4>
<p>If you have an arbitrary byte slice, you can't really do it any other way since it might not be properly aligned to be accessed any other way.</p>



<a name="152137923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137923">(Dec 18 2018 at 20:59)</a>:</h4>
<p>yeah not looking for a different way, just wanting to confirm that has the intended semantics</p>



<a name="152137946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137946">(Dec 18 2018 at 20:59)</a>:</h4>
<p>Presumably you are getting the pointer that you pass to <code>write_volatile</code> from a reference.</p>



<a name="152137952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152137952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152137952">(Dec 18 2018 at 20:59)</a>:</h4>
<p>probably a reference to a slice.</p>



<a name="152138009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152138009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152138009">(Dec 18 2018 at 21:00)</a>:</h4>
<p>References are (assumed to be) always properly aligned so your pointer will always be properly aligned.</p>



<a name="152138197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152138197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152138197">(Dec 18 2018 at 21:03)</a>:</h4>
<p>FWIW, I still prefer the ISO C semantics for <code>volatile</code> where it is used to describe objects, not accesses to objects.</p>



<a name="152159969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152159969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152159969">(Dec 19 2018 at 05:13)</a>:</h4>
<p>well, if this is semantically correct... <a href="https://github.com/iqlusioninc/crates/pull/142/files" target="_blank" title="https://github.com/iqlusioninc/crates/pull/142/files">https://github.com/iqlusioninc/crates/pull/142/files</a></p>



<a name="152159988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152159988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152159988">(Dec 19 2018 at 05:13)</a>:</h4>
<p>not sure what else to say but "wow"</p>



<a name="152159994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152159994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152159994">(Dec 19 2018 at 05:13)</a>:</h4>
<p><a href="/user_uploads/4715/g3yUTu18hxTFMO8s84KcVhn-/Screen-Shot-2018-12-18-at-9.12.47-PM.png" target="_blank" title="Screen-Shot-2018-12-18-at-9.12.47-PM.png">Screen-Shot-2018-12-18-at-9.12.47-PM.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/g3yUTu18hxTFMO8s84KcVhn-/Screen-Shot-2018-12-18-at-9.12.47-PM.png" target="_blank" title="Screen-Shot-2018-12-18-at-9.12.47-PM.png"><img src="/user_uploads/4715/g3yUTu18hxTFMO8s84KcVhn-/Screen-Shot-2018-12-18-at-9.12.47-PM.png"></a></div>



<a name="152214312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152214312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152214312">(Dec 19 2018 at 21:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> so I was looking at the generated assembly from ^^^ PR... it does more or less what you'd expect on a byte slice: loops over it doing <code>mov</code> and setting each byte to 0</p>



<a name="152214394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152214394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152214394">(Dec 19 2018 at 21:26)</a>:</h4>
<p>I totally plan on landing that PR, but I was looking at <code>volatile_set_memory</code> and it just calls <code>memset</code>, so I'm still wondering "what would a stable API for (volatile) memset look like"?</p>



<a name="152214433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152214433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152214433">(Dec 19 2018 at 21:27)</a>:</h4>
<p>I could imagine in a future with specialization and a stable wrapper for that I could specialize handling of <code>&amp;[u8]</code> which so happens to be the main case I care about</p>



<a name="152214910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152214910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152214910">(Dec 19 2018 at 21:35)</a>:</h4>
<p>the only difference really being that the stable API (<code>write_volatile</code>) writes "one <code>T</code> worth" of memory, and you'd prefer to have an <code>n</code> value, basically?</p>



<a name="152215001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215001">(Dec 19 2018 at 21:37)</a>:</h4>
<p><span class="user-mention" data-user-id="132721">@Tony Arcieri</span> I think it is OK for <code>volatile_set_memory</code> to just call memset as long as the IR indicates that the call cannot be removed. In general, what's really relevant is the IR, not the generated assembly.</p>



<a name="152215014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215014">(Dec 19 2018 at 21:37)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> yep!</p>



<a name="152215021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215021">(Dec 19 2018 at 21:37)</a>:</h4>
<p><span class="user-mention" data-user-id="133214">@briansmith</span> I want memset!</p>



<a name="152215022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215022">(Dec 19 2018 at 21:37)</a>:</h4>
<p>the problem is <code>volatile_set_memory</code> isn't stable</p>



<a name="152215164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215164">(Dec 19 2018 at 21:39)</a>:</h4>
<p>the C equivalent of what I'd actually want is:</p>
<div class="codehilite"><pre><span></span>memset(dest, &#39;\0&#39;, n);
asm volatile (&quot;&quot; ::: &quot;memory&quot;);
</pre></div>



<a name="152215633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215633">(Dec 19 2018 at 21:46)</a>:</h4>
<p>Ideally you'd want semantics that are like "treat this as a volatile write unless something else would overwrite what it would write"</p>



<a name="152215647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215647">(Dec 19 2018 at 21:46)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> crazy idea: <code>set_volatile()</code> or <code>fill_volatile()</code> on the <code>slice</code> primitive</p>



<a name="152215750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215750">(Dec 19 2018 at 21:48)</a>:</h4>
<p>or <code>[u8]</code> specifically would be fine</p>



<a name="152215787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152215787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152215787">(Dec 19 2018 at 21:49)</a>:</h4>
<p>It wouldn't be good to limit it only to <code>u8</code>. In fact most secret data probably shouldn't be in <code>u8</code> arrays.</p>



<a name="152216254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152216254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152216254">(Dec 19 2018 at 21:57)</a>:</h4>
<p><code>memset_s</code> I assume?</p>



<a name="152216534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152216534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152216534">(Dec 19 2018 at 22:01)</a>:</h4>
<p><span class="user-mention" data-user-id="130046">@Alex Gaynor</span> volatile memset, yeah</p>



<a name="152216667"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152216667" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152216667">(Dec 19 2018 at 22:03)</a>:</h4>
<p><span class="user-mention" data-user-id="133214">@briansmith</span> yeah, <code>[u8]</code> was in the context of "in a future Rust with specialization, I could specialize the implementation of <code>Zeroize</code> for <code>[u8]</code>". good enough for my purposes but I'd agree a more general primitive would be better. instead of specializing a faster implementation just for <code>[u8]</code>, I could have something that's fast for all supported types</p>



<a name="152217929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152217929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152217929">(Dec 19 2018 at 22:25)</a>:</h4>
<p>but yeah anyway, this is all a microoptimization. in the meantime I'll be moving forward with what I've got even if it's slower</p>



<a name="152218041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218041">(Dec 19 2018 at 22:27)</a>:</h4>
<p>getting rid of the yucky OS-specific API bindings would be worth it alone, but it's nice how easily this generalizes to all of the primitive number types</p>



<a name="152218119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218119">(Dec 19 2018 at 22:28)</a>:</h4>
<p>this was a bit surprising: <a href="https://github.com/iqlusioninc/crates/blob/d9ec89ada4e89b6c9a9333ff9c67c650a35455af/zeroize/src/lib.rs#L100" target="_blank" title="https://github.com/iqlusioninc/crates/blob/d9ec89ada4e89b6c9a9333ff9c67c650a35455af/zeroize/src/lib.rs#L100">https://github.com/iqlusioninc/crates/blob/d9ec89ada4e89b6c9a9333ff9c67c650a35455af/zeroize/src/lib.rs#L100</a></p>



<a name="152218127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218127">(Dec 19 2018 at 22:28)</a>:</h4>
<p>the same macro works on <code>char</code> <span class="emoji emoji-1f62e" title="open mouth">:open_mouth:</span></p>



<a name="152218129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218129">(Dec 19 2018 at 22:28)</a>:</h4>
<p>not sure that's actually doing what I want</p>



<a name="152218143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218143">(Dec 19 2018 at 22:28)</a>:</h4>
<p>possibly doing something unsafe <span class="emoji emoji-1f605" title="sweat smile">:sweat_smile:</span></p>



<a name="152218507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218507">(Dec 19 2018 at 22:35)</a>:</h4>
<p><span class="user-mention" data-user-id="132721">@Tony Arcieri</span> Couldn't you <code>impl Zeroize for T where T: Default</code>without any macro?</p>



<a name="152218597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218597">(Dec 19 2018 at 22:36)</a>:</h4>
<p><code>Default</code> is implemented on things like <code>Vec&lt;T&gt;</code>, where this wouldn't work, would it?</p>



<a name="152218684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152218684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152218684">(Dec 19 2018 at 22:38)</a>:</h4>
<p>Good point.</p>



<a name="152258116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152258116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152258116">(Dec 20 2018 at 14:04)</a>:</h4>
<p><span class="user-mention" data-user-id="133214">@briansmith</span> haha, came across this thread where you seem to be asking the questions I'm curious about now <a href="https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/24" target="_blank" title="https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/24">https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/24</a></p>



<a name="152258151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152258151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152258151">(Dec 20 2018 at 14:05)</a>:</h4>
<p>was looking specifically at this in the <code>write_volatile</code> docs</p>



<a name="152258157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152258157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152258157">(Dec 20 2018 at 14:05)</a>:</h4>
<blockquote>
<p>Memory accessed with read_volatile or write_volatile should not be accessed with non-volatile operations.</p>
</blockquote>



<a name="152258443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152258443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152258443">(Dec 20 2018 at 14:08)</a>:</h4>
<p>Now I better understand what you're getting at here:</p>
<blockquote>
<p>FWIW, I still prefer the ISO C semantics for <code>volatile</code> where it is used to describe objects, not accesses to objects.</p>
</blockquote>



<a name="152274896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152274896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152274896">(Dec 20 2018 at 18:05)</a>:</h4>
<p>Yes, I spent a significant amount of time trying this idea before. Note in particular that any movable type (i.e. basically all types) do have non-volatile accesses when they are moved.</p>



<a name="152274906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152274906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152274906">(Dec 20 2018 at 18:05)</a>:</h4>
<p>And, obviously, the same for <code>Copy</code></p>



<a name="152275986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152275986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152275986">(Dec 20 2018 at 18:22)</a>:</h4>
<p>yep, I already have a whole disclaimer in my README about that sort of thing</p>



<a name="152276034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152276034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152276034">(Dec 20 2018 at 18:23)</a>:</h4>
<p>noting the <code>Pin</code> RFC</p>



<a name="152276150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152276150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152276150">(Dec 20 2018 at 18:25)</a>:</h4>
<p>here's my WIP text... I'm about to mention ^^^ internals.rust-lang thread and <span class="user-mention" data-user-id="116009">@nikomatsakis</span>'s response at the very end:</p>
<div class="codehilite"><pre><span></span>## What guarantees does this crate provide?

Ideally a memory-zeroing function would do two things:

1. Ensure the zeroing operation can&#39;t be &quot;optimized away&quot; by the compiler.
2. Ensure all subsequent reads to the memory following the zeroing operation
   will always see zeroes.

This crate guarantees #1 is true: LLVM&#39;s volatile semantics ensure it.

The story around #2 is much more complicated. In brief, it should be true that
LLVM&#39;s current implementation does not attempt to perform optimizations which
would allow a subsequent (non-volatile) read to see the original value prior
to zeroization. However, this is not a guarantee, but rather an LLVM
implementation detail.

For more background, we can look to the [std::ptr::write_volatile()]
documentation:

&gt; Volatile operations are intended to act on I/O memory, and are guaranteed
&gt; to not be elided or reordered by the compiler across other volatile
&gt; operations.
&gt;
&gt; Memory accessed with read_volatile or write_volatile should not be accessed
&gt; with non-volatile operations.

Uhoh! This crate does not guarantee all reads to the memory it operates on are
volatile, and explicitly warns against mixing volatile and non-volatile
operations. Perhaps we&#39;d be better off with something like a `VolatileCell`
type which owns the associated data and ensures all reads and writes are
volatile so we don&#39;t have to worry about the semantics of mixing volatile and
non-volatile accesses.

While that&#39;s a strategy worth pursuing (and something we may investigate
separately from this crate), it comes with some onerous API requirements:
it means any data that we might ever desire to zero is owned by a
`VolatileCell`. However, this does not make it possible for this crate
to act on references, which severely limits its applicability.

It&#39;s worth asking what the semantics of mixing volatile and non-volatile reads
actually are, and whether a less obtrusive API which can act entirely on
mutable references is possible, safe, and provides the desired behavior.
Unfortunately, that&#39;s a tricky question, because Rust does not have a formally
defined memory model, and the behavior of mixing volatile and non-volatile
memory accesses winds up largely being an LLVM implementation detail.

[To Be Continued]
</pre></div>



<a name="152276337"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152276337" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152276337">(Dec 20 2018 at 18:27)</a>:</h4>
<p>err reading over my own text I'm seeing a few things I need to rewrite <span class="emoji emoji-1f609" title="wink">:wink:</span></p>



<a name="152276393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152276393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152276393">(Dec 20 2018 at 18:28)</a>:</h4>
<blockquote>
<p>This crate does not guarantee all reads to the memory it operates on are volatile, and explicitly warns against mixing volatile and non-volatile<br>
operations</p>
</blockquote>



<a name="152276402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152276402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152276402">(Dec 20 2018 at 18:28)</a>:</h4>
<p>need to reword that in particular</p>



<a name="152298996"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152298996" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152298996">(Dec 21 2018 at 00:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> so based on your response here: <a href="https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/46" target="_blank" title="https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/46">https://internals.rust-lang.org/t/volatile-and-sensitive-memory/3188/46</a></p>



<a name="152299038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299038">(Dec 21 2018 at 00:44)</a>:</h4>
<p>it seems like the best path forward is something that has <code>VolatileCell</code>-like semantics</p>



<a name="152299042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299042">(Dec 21 2018 at 00:44)</a>:</h4>
<p>i.e. it owns the data, and ensures <em>all</em> accesses are volatile</p>



<a name="152299047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299047">(Dec 21 2018 at 00:44)</a>:</h4>
<p>something like that, plus <code>Pin</code></p>



<a name="152299069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299069">(Dec 21 2018 at 00:45)</a>:</h4>
<p>and I think you can enforce fairly reasonable zeroization semantics, which are:</p>



<a name="152299071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299071">(Dec 21 2018 at 00:45)</a>:</h4>
<p>1) don't make (non-explicit) copies</p>



<a name="152299078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299078">(Dec 21 2018 at 00:45)</a>:</h4>
<p>2) don't allow non-volatile accesses</p>



<a name="152299135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299135">(Dec 21 2018 at 00:46)</a>:</h4>
<p>3) the "zeroization" operation (which can now be performed on <code>Drop</code>) is guaranteed not to be "optimized away" or otherwise elided by the compiler</p>



<a name="152299137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299137">(Dec 21 2018 at 00:46)</a>:</h4>
<p>would you agree?</p>



<a name="152299172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299172">(Dec 21 2018 at 00:47)</a>:</h4>
<p>just wondering if I'm missing something here</p>



<a name="152299204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299204">(Dec 21 2018 at 00:47)</a>:</h4>
<p>re: what I have in ^^^ PR to <code>zeroize</code> it is... "Not Optimal" because it mixes volatile and non-volatile accesses</p>



<a name="152299296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299296">(Dec 21 2018 at 00:49)</a>:</h4>
<p>also I was wondering if <code>core::sync::atomic::compiler_fence</code> and/or <code>core::sync::atomic::fence</code> can provide reliable, portable semantics for mixing volatile and non-volatile accesses</p>



<a name="152299303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152299303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152299303">(Dec 21 2018 at 00:49)</a>:</h4>
<p>I have never used either and do not have a good sense of what either do</p>



<a name="152301233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152301233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152301233">(Dec 21 2018 at 01:31)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> also any thoughts on something like <code>VolatileCell</code> in <code>core</code>/<code>std</code>?</p>



<a name="152364729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152364729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152364729">(Dec 21 2018 at 23:09)</a>:</h4>
<p>so <code>VolatileCell</code> for this purpose has a big drawback: it reads an owned value. if the goal is to erase a secret, making copies of it to read it seems... suboptimal</p>



<a name="152392044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152392044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152392044">(Dec 22 2018 at 14:59)</a>:</h4>
<p>added memory fences... and also a marker trait for zeroizing using the <code>Default</code> value which when used as the trait bound for things like collections allows them to only be used once at the end of the collection <a href="https://github.com/iqlusioninc/crates/pull/146/files" target="_blank" title="https://github.com/iqlusioninc/crates/pull/146/files">https://github.com/iqlusioninc/crates/pull/146/files</a></p>



<a name="152392180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152392180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152392180">(Dec 22 2018 at 15:02)</a>:</h4>
<p>was also able to add special-case optimizations on <code>nightly</code> for <code>[u8]</code> and <code>[u8; N]</code> which are the main cases I care about</p>



<a name="152392188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/152392188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#152392188">(Dec 22 2018 at 15:03)</a>:</h4>
<p>using <code>volatile_set_memory</code></p>



<a name="154205183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154205183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154205183">(Jan 02 2019 at 22:12)</a>:</h4>
<blockquote>
<p>it seems like the best path forward is something that has <code>VolatileCell</code>-like semantics</p>
</blockquote>
<p>I'm trying to bring this back in cache -- I know that <span class="user-mention" data-user-id="120791">@RalfJ</span> and I were talking about this sort of thing from time to time in conjunction with the work on stacked borrows and other parts of the unsafe-code-guidelines. To some extent, a <code>union</code> may already fit the bill here as well, since the compiler is not generally permitted to assume that the contents are valid</p>



<a name="154205199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154205199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154205199">(Jan 02 2019 at 22:13)</a>:</h4>
<p>I feel like the upcoming topic for the unsafe-code-guidelines discussion -- which will be a focus on the invariants that have to hold for various types -- is going to be very apropos</p>



<a name="154205211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154205211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154205211">(Jan 02 2019 at 22:13)</a>:</h4>
<p>(that said, the LLVM treatment of unions may not be sufficiently conservative I suppose, so maybe there is still a need for a volatile cell sort of thing)</p>



<a name="154205253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154205253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154205253">(Jan 02 2019 at 22:14)</a>:</h4>
<p>I guess the question is whether there are optimizations we could do on unions that would be ruled out by volatile cell</p>



<a name="154208543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154208543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154208543">(Jan 02 2019 at 23:26)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> upon further reflection <code>VolatileCell</code> is the opposite of what I want... it makes a copy each time data is read, and I'm trying to reduce the number of copies to 0 <span class="emoji emoji-1f609" title="wink">:wink:</span></p>



<a name="154232573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154232573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154232573">(Jan 03 2019 at 10:52)</a>:</h4>
<blockquote>
<p>FWIW, I still prefer the ISO C semantics for volatile where it is used to describe objects, not accesses to objects.</p>
</blockquote>
<p>That's not correct: ISO C also allows volatile <em>accesses</em>, you can cast a pointer to a volatile pointer and use that. adding volatile objects adds lots of complexity for no gain at all. In the best case, a definition in terms of objects can coincide with the access-based definition for the case where there is no object with mixed accesses.</p>
<p>Personally, I never understood volatile objects, for many years. then somewhere I found an explanation in terms of accesses and suddenly everything made sense. Also note that the concurrency memory model is entirely defined in terms of accesses, not objects.<br>
I am still curious why you think this makes more sense for objects -- but we've had this discussion before and did not get very far.</p>



<a name="154232647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154232647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154232647">(Jan 03 2019 at 10:54)</a>:</h4>
<p>Volatile objects make sense as a high-level API, just like we have "atomic objects" like <code>AtomicUsize</code>. But they are the wrong level of abstraction for defining the semantics.</p>



<a name="154232728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154232728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154232728">(Jan 03 2019 at 10:56)</a>:</h4>
<blockquote>
<p>it seems like the best path forward is something that has VolatileCell-like semantics<br>
i.e. it owns the data, and ensures all accesses are volatile</p>
</blockquote>
<p>agreed. and you can define this entirely as a library, just like <code>AtomicUsize</code>.</p>
<blockquote>
<p>so VolatileCell for this purpose has a big drawback: it reads an owned value. if the goal is to erase a secret, making copies of it to read it seems... suboptimal</p>
</blockquote>
<p>what do you mean by this?</p>



<a name="154236389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154236389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154236389">(Jan 03 2019 at 12:21)</a>:</h4>
<p>one potential issue here is the <code>dereferencable</code> attribute; for that, also see  <a href="https://github.com/rust-lang/rust/issues/55005" target="_blank" title="https://github.com/rust-lang/rust/issues/55005">https://github.com/rust-lang/rust/issues/55005</a></p>



<a name="154241640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154241640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154241640">(Jan 03 2019 at 14:16)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> naively it looks like <code>VolatileCell</code> performs a volatile read but leaves a copy of the data on the stack</p>



<a name="154241644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154241644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154241644">(Jan 03 2019 at 14:16)</a>:</h4>
<p>which is literally the opposite of what I want</p>



<a name="154242330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154242330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154242330">(Jan 03 2019 at 14:28)</a>:</h4>
<p><code>VolatileCell</code> is a type, not an operation, it doesn't do anything.^^ which method are you referring to?</p>



<a name="154242441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154242441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154242441">(Jan 03 2019 at 14:30)</a>:</h4>
<p>but also, all of rustc, LLVM (and also GCC, ...) dont have a notion of data being secret, so you'll always be fighting their optimizers etc because you are making a difference between behaviors that they deem equivalent</p>



<a name="154242851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154242851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154242851">(Jan 03 2019 at 14:37)</a>:</h4>
<p>I'm specifically referring to the accessors, which work on values, not references, e.g. <a href="https://github.com/japaric/vcell/blob/master/src/lib.rs#L43" target="_blank" title="https://github.com/japaric/vcell/blob/master/src/lib.rs#L43">https://github.com/japaric/vcell/blob/master/src/lib.rs#L43</a></p>



<a name="154242901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154242901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154242901">(Jan 03 2019 at 14:38)</a>:</h4>
<p>unless I'm mistaken, that's making a copy of a value onto the stack</p>



<a name="154246617"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154246617" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154246617">(Jan 03 2019 at 15:39)</a>:</h4>
<p>what else would <code>get</code> do? you asked to get access to the value directly, of course that puts it outside the cell</p>



<a name="154247102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154247102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154247102">(Jan 03 2019 at 15:47)</a>:</h4>
<p>well going back to my original comment you were asking about...</p>



<a name="154247105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154247105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154247105">(Jan 03 2019 at 15:47)</a>:</h4>
<blockquote>
<p>so VolatileCell for this purpose has a big drawback: it reads an owned value. if the goal is to erase a secret, making copies of it to read it seems... suboptimal</p>
</blockquote>



<a name="154247111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154247111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154247111">(Jan 03 2019 at 15:47)</a>:</h4>
<p>I don't want to make copies</p>



<a name="154247124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154247124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154247124">(Jan 03 2019 at 15:47)</a>:</h4>
<p>I am trying to delete existing copies</p>



<a name="154248256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154248256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154248256">(Jan 03 2019 at 16:04)</a>:</h4>
<p>why do you call <code>get</code> if you want to erase a secret...?</p>



<a name="154248263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154248263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154248263">(Jan 03 2019 at 16:04)</a>:</h4>
<p>I think you're misunderstanding what I'm saying</p>



<a name="154248272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154248272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154248272">(Jan 03 2019 at 16:04)</a>:</h4>
<p><code>VolatileCell</code> doesn't solve my problem so I'm not using it</p>



<a name="154248274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154248274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154248274">(Jan 03 2019 at 16:04)</a>:</h4>
<p>I think so too :)</p>



<a name="154261126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154261126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154261126">(Jan 03 2019 at 19:34)</a>:</h4>
<blockquote>
<blockquote>
<p>FWIW, I still prefer the ISO C semantics for volatile where it is used to describe objects, not accesses to objects.</p>
</blockquote>
<p>That's not correct: ISO C also allows volatile <em>accesses</em>, you can cast a pointer to a volatile pointer and use that.</p>
</blockquote>
<p>I don't think that is right. The C standard consistently uses the phrase "object defined with a volatile-qualified type", says accessing these kinds of objects through volatile-qualified types is implementation defined, and says using them as non-volatile-qualified lvaules is undefined behavior. It doesn't require an implementation to give volatile semantics to objects it knows are not volatile even if they are exclusively accessed through volatile pointers. However, there is a recent proposal by a Googler to change this to the LLVM semantics.</p>



<a name="154261448"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154261448" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> briansmith <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154261448">(Jan 03 2019 at 19:39)</a>:</h4>
<p>Regardless of that, I understand that at this point it isn't useful to debate what Rust will do w.r.t. volatile. I prefer the C way, except without the ridiculous ease of (accidentally) wrongly casting from volatile &lt;-&gt; non-volatile in ways that don't work, but I understand that it is unlikely that Rust would change to that any time soon, especially because rustc will be using LLVM; it seems easier to change the C standard than to change LLVM, as evidenced by Google's proposal.</p>



<a name="154402199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154402199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154402199">(Jan 04 2019 at 11:00)</a>:</h4>
<p>another reason we should prefer volatile accesses IMO is that there's a trivial translation from a "volatile-object" based world to a "volatile-access" based world -- every access to a volatile object is a volatile access, done. there is no translation possible in general the other way. so, volatile accesses are strictly more general.</p>



<a name="154402419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/154402419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#154402419">(Jan 04 2019 at 11:06)</a>:</h4>
<blockquote>
<p>The C standard consistently uses the phrase "object defined with a volatile-qualified type", says accessing these kinds of objects through volatile-qualified types is implementation defined, and says using them as non-volatile-qualified lvaules is undefined behavior.</p>
</blockquote>
<p>Indeed, I misremembered.</p>
<blockquote>
<p>It doesn't require an implementation to give volatile semantics to objects it knows are not volatile even if they are exclusively accessed through volatile pointers.</p>
</blockquote>
<p>A possible reading of the standard is that having a volatile-qualified lvalue makes the object in that lvalue a volatile object.</p>
<p>Notice that it's not just LLVM that thinks of volatile as being an access-qualifier; the Linux kernel does that a lot so this is for sure also the way GCC handles volatile.</p>



<a name="166194127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/166194127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#166194127">(May 21 2019 at 17:36)</a>:</h4>
<p>nice, thanks <span class="user-mention" data-user-id="120791">@RalfJ</span> <a href="https://github.com/rust-lang/rust/pull/60972" target="_blank" title="https://github.com/rust-lang/rust/pull/60972">https://github.com/rust-lang/rust/pull/60972</a></p>



<a name="166194225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/166194225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#166194225">(May 21 2019 at 17:37)</a>:</h4>
<p>I feel guilty because I was involved in adding this text (and didn't foresee the confusion it would cause), so this is only fair ;)</p>



<a name="166252548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/Zeroize%20%28https%3A//crates.io/crates/zeroize%29/near/166252548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevQps <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/Zeroize.20(https.3A.2F.2Fcrates.2Eio.2Fcrates.2Fzeroize).html#166252548">(May 22 2019 at 09:50)</a>:</h4>
<p>Nice work indeed! (Y)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>